﻿// =====================================================================
// <copyright file="SettingItem.cs" author="David R. Guindo">
// 	Copyright (C) 2013. All rights reserved.
// </copyright>
// =====================================================================

namespace AppBlock.Config
{
   using Newtonsoft.Json;

   public class SettingItem
   {
      public string Group { get; set; }

      public string Key { get; set; }

      public virtual string Module { get; set; }

      public virtual string SerializedValue { get; set; }

      public virtual string UserId { get; set; }

      public object GetValue<T>()
      {
         if (string.IsNullOrWhiteSpace(this.SerializedValue))
         {
            return null;
         }
         return JsonConvert.DeserializeObject<T>(this.SerializedValue);
      }

      public void SetValue<T>(T value) { this.SerializedValue = JsonConvert.SerializeObject(value); }
   }
}